/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dds2.serviceSystem.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dds2.ServicesSystem.Enum.TransactionState;
import mx.its.dds2.ServicesSystem.Modelo.Service;
import mx.its.dds2.serviceSystem.Dao.ServiceDaoLocal;

/**
 *
 * @author Carlos Asis
 */
@Stateless
public class ServiceBl implements ServiceBlLocal {
    @EJB
    private ServiceDaoLocal serviceDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
     @Override
    public TransactionState register(Service service) {
        if (serviceDao.FindDuplecity(service)) {
            return TransactionState.INCOMPLETE;
        } else {
            serviceDao.create(service);
            return TransactionState.COMPLETE;
        }

    }

    @Override
    public TransactionState modify(Service service) {
        if (service.getId() == null || serviceDao.find(service.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            serviceDao.edit(service);
            return TransactionState.COMPLETE;
        }
    }

    @Override
    public TransactionState delete(Service service) {
        if (service.getId() == null || serviceDao.find(service.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            serviceDao.remove(service);
            return TransactionState.COMPLETE;
        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public List<Service> getListAll() {
        return serviceDao.findAll();
    }

    
}
